package com.hjj.services;

import com.hjj.beans.ActivitiesRemark;
import com.hjj.mapper.ActivitiesRemarkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

@Service
public class ActivitiesRemarkServicesImp implements ActivitiesRemarkServices{
    @Autowired
    ActivitiesRemarkMapper activitiesRemarkMapper;

    @Override
    public ActivitiesRemark get(String id) {
        return activitiesRemarkMapper.get(id);
    }

    @Override
    public boolean add(ActivitiesRemark activitiesRemark) {
        // 给备注数据添加UUID
        activitiesRemark.setId(UUID.randomUUID().toString().replace("-", ""));

        // 给备注数据添加创建时间
        activitiesRemark.setNoteTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

        // 添加数据时初始化数据标记
//        activitiesRemark.setEditFlag(0);

        return activitiesRemarkMapper.add(activitiesRemark) > 0 ? true : false;
    }

    @Override
    public boolean edit(ActivitiesRemark activitiesRemark) {
        // 给备注添加修改时间
        activitiesRemark.setEditTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

        // 备注添加修改标记
        activitiesRemark.setEditFlag(1);


        return activitiesRemarkMapper.edit(activitiesRemark) > 0 ? true : false;
    }

    @Override
    public boolean del(String id) {
        return activitiesRemarkMapper.del(id) > 0 ? true : false;
    }
}
